/*
 * Copyright (C) 2009 Rafael Fernandes
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.phonebooksharing.services.ejb3.facade;

import javax.ejb.Stateless;

import org.apache.commons.lang.math.RandomUtils;
import org.apache.log4j.Logger;

import com.phonebooksharing.dto.gallery.PostCardItem;
import com.phonebooksharing.dto.msg.VoiceMessageItem;
import com.phonebooksharing.services.ejb3.utils.IConstants;

/**
 * Stateless EJB Bean with contains the facade logic which performs 
 * the desired lookups and business logic required by its method.
 * 
 * <p> Should always return an object that will be serialized by its 
 * caller and sent back to Android.
 * 
 * @author <a href='mailto:luizrafael@gmail.com'>Rafael Fernandes</a>
 *
 */
@Stateless
public class MessageFacadeBean implements MessageFacade {
    private static Logger log = Logger.getLogger(MessageFacadeBean.class);
    
    @Override
    public VoiceMessageItem create(String authItem, VoiceMessageItem voice) {
        voice.voiceMessageID = RandomUtils.nextLong() * 1000; //just add an id to id
        return voice;
    }

    @Override
    public void updateVoicePathTemp(Long id, String path) {
        //void
        log.info("updateVoicePathTemp, id [" + id + "], path [" + path + "]");
    }

    @Override
    public void createResponse(String authItem, long dashboardID, VoiceMessageItem voice) {
        //void
        log.info("createResponse, authItem [" + authItem + "], dashboardID [" + dashboardID + "]");
    }

    @Override
    public PostCardItem create(String authItem, PostCardItem postcard) {
        postcard.postcardID = RandomUtils.nextLong() * 1000; //just add an id to id
        return postcard;
    }

    @Override
    public void updatePostcardBackPathTemp(Long id, String path) {
        //void
        log.info("updatePostcardBackPathTemp, id [" + id + "], path [" + path + "]");
    }

    @Override
    public void updatePostcardFrontPathTemp(Long id, String path) {
        //void
        log.info("updatePostcardFrontPathTemp, id [" + id + "], path [" + path + "]");
    }

    @Override
    public String getPostcardFrontPath(Long postcardID) {
        int anID = 3089;
        return String.format(IConstants.ROOT_FOR_POSTCARD + "f%s.jpg", anID);//the path should be valid in the server with an image on.
    }
    
    @Override
    public String getPostcardBackPath(Long postcardID) {
        int anID = 3089;
        return String.format(IConstants.ROOT_FOR_POSTCARD + "b%s.jpg", anID);//the path should be valid in the server with an image on.
    }

    @Override
    public String getAudioPath(Long audioID) {
        int anID = 3089;
        return String.format(IConstants.ROOT_FOR_VOICE + "%s.3gpp", anID);//the path should be valid in the server with a 3gpp audio on.
    }
}
